package com.admin.exam.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.admin.base.Page;
import com.admin.base.BaseController;
import com.admin.base.Response;
import com.admin.exam.entity.Hospital;
import com.admin.exam.service.HospitalService;
import com.admin.exam.vo.query.HospitalQuery;

/**
 * 
 */
@Controller
@RequestMapping(value = "/exam/hospital")
public class HospitalController extends BaseController{

	@Autowired
	HospitalService hospitalService;

	/**
	 * 列表页面
	 */
	@RequestMapping(value = "/list")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response, ModelAndView mav) {
		mav.setViewName("exam/hospital/list");
		return mav;
	}

	/**
	 * 分页查询数据
	 */
	@RequestMapping(value = "/paging")
	@ResponseBody
	public Response paging(HttpServletRequest request, HttpServletResponse response, HospitalQuery query) {
		Page<Hospital> page = hospitalService.pagingByConditions(query);
		return Response.ok(page);
	}

	/**
	 * 新增页面
	 */
	@RequestMapping(value = "/toAdd")
	public ModelAndView toAdd(HttpServletRequest request, HttpServletResponse response, ModelAndView mav) {
		mav.setViewName("exam/hospital/add");
		return mav;
	}

	/**
	 * 保存数据
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Response add(HttpServletRequest request, HttpServletResponse response, Hospital hospital) {
		hospitalService.add(hospital);
		return Response.ok();
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Response delete(HttpServletRequest request, HttpServletResponse response, Integer[] id) {
		hospitalService.delete(id);
		return Response.ok();
	}

	/**
	 * 编辑页面
	 */
	@RequestMapping(value = "/toEdit")
	public ModelAndView toEdit(HttpServletRequest request, HttpServletResponse response, ModelAndView mav, Integer id) {
		Hospital hospital = hospitalService.getById(id);
		mav.addObject(hospital);
		mav.setViewName("exam/hospital/edit");
		return mav;
	}

	/**
	 * 详情页面
	 */
	@RequestMapping(value = "/detail")
	public ModelAndView detail(HttpServletRequest request, HttpServletResponse response, ModelAndView mav, Integer id) {
		Hospital hospital = hospitalService.getById(id);
		mav.addObject(hospital);
		mav.setViewName("exam/hospital/detail");
		return mav;
	}

	/**
	 * 更新数据
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Response update(HttpServletRequest request, HttpServletResponse response, Hospital hospital) {
		hospitalService.update(hospital);
		return Response.ok();
	}
}
